package com.example.perpetualcalendar.ui.fragment.history;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.perpetualcalendar.R;
import com.example.perpetualcalendar.adapter.MyAdapter;
import com.example.perpetualcalendar.base.BaseFragment;
import com.example.perpetualcalendar.databinding.FragmentNotificationsBinding;
import com.example.perpetualcalendar.databinding.HistoryFragmentBinding;
import com.example.perpetualcalendar.domain.entity.History;
import com.example.perpetualcalendar.ui.fragment.joke.JokeViewModel;

import java.util.List;

public class HistoryFragment extends BaseFragment<HistoryViewModel, HistoryFragmentBinding> {

    MyAdapter myAdapter;

    @Override
    protected void initView() {
        mViewModel.getResultDTO().observe(getViewLifecycleOwner(), new Observer<List<History.ResultDTO>>() {
            @Override
            public void onChanged(List<History.ResultDTO> resultDTOS) {
                Log.d("TAG", "onChanged: "+resultDTOS.size());
                if(myAdapter==null){
                    myAdapter = new MyAdapter(resultDTOS);
                    viewBinding.listHistory.setAdapter(myAdapter);
                }else {
                    myAdapter.notifyDataSetChanged();
                }
            }
        });
    }

    @NonNull
    @Override
    protected Class<HistoryViewModel> setViewModel() {
        return HistoryViewModel.class;
    }

    @NonNull
    @Override
    protected int setLayout() {
        return R.layout.history_fragment;
    }
}